﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace huaguwang.hgmanage.Power
{
    public partial class LogSee : System.Web.UI.Page
    {
        #region 固定方法

        readonly D_T_MenterGroup_Log_Exp _Dal = new D_T_MenterGroup_Log_Exp();

        private void SetBut(int i, Button but)
        {
            switch(i)
            {
                case 0:
                    but.Attributes.Add("onclick", "return GetDelCheckDefault();");
                    break;
                default:
                    break;
            }
        }
        private huaguwang.WebControls.WebUserToolBar.SelectItem[] SetText()
        {
            huaguwang.WebControls.WebUserToolBar.SelectItem[] list = { 
                new huaguwang.WebControls.WebUserToolBar.SelectItem(){
                    FuncGetText=()=>TextBox2.Text.Exp_Trim(),
                    FuncSetText=V=>{TextBox2.Text=V;},
                    Name=TextBox2.ID
                },                                                                     
                   new huaguwang.WebControls.WebUserToolBar.SelectItem(){
                    FuncGetText=()=>TextBox1.Text.Exp_Trim(),
                    FuncSetText=V=>{TextBox1.Text=V;},
                    Name=TextBox1.ID
                },     
                                                                     
            };
            return list;
        }
        /// <summary>
        /// 查询的实现方法
        /// </summary>
        /// <param name="begin"></param>
        private void SetData(int begin)
        {
            AdminPublic.Try(() =>
            {
                var txtPName = WebUserToolBar1.MainGetQuery(TextBox1.ID);
                var txtName = WebUserToolBar1.MainGetQuery(TextBox2.ID);
                Pager.RecordCount = _Dal.Find(txtPName, txtName);
                this.Repeater1.DataSource = _Dal.
                        Find(begin, Pager.PageSize, txtPName, txtName);
                this.Repeater1.DataBind();
            });
        }

        #endregion


        protected void Page_Load(object sender, EventArgs e)
        {
            AdminPublic.Try(() =>
            {
                Pager.PageSize = 10;
                //用来初始化用户的按钮,执行此语句的时候,but并没有具体产生
                this.WebUserToolBar1.MainInit(
                    UserConst.Exp_GetUser,
                    UserConst.Exp_GetButtonList,
                    SetBut,
                    UserConst.Exp_ToolBarErr,
                    SetText()
                );


                if(!IsPostBack)
                {
                    //分页查询
                    SetData(0);
                }
            });

        }




        #region 基本的带有查询的事件组合

        /// <summary>
        /// 分页控件的页面事件
        /// </summary>
        /// <param name="src"></param>
        /// <param name="e"></param>
        protected void Pager_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AdminPublic.Try(() =>
            {
                SetData((e.NewPageIndex - 1) * Pager.PageSize);
            });
        }

         
         

         
        /// <summary>
        /// 删除按钮的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void WebUserToolBar1_DEL(object sender, EventArgs e)
        {
            
            //this.Exp_PageAlter("获得了" + strID);
        }
        #endregion

        protected void WebUserToolBar1_Button4(object sender, EventArgs e)
        {
          

        }

        protected void WebUserToolBar1_Button0(object sender, EventArgs e)
        {
            AdminPublic.Try(() =>
            {
                var strID = Request.Params["HiddenID"].Exp_Trim();
                var intA = strID.Exp_SplitToList(',', Sel => Sel.Exp_IntTryParse()).Where(Sel => Sel > 0).ToList();
                if(intA == null || intA.Count <= 0)
                {
                    this.Exp_PageAlter("没有找到可以删除的信息");
                    return;
                }

                int i = 0;
                foreach(var item in intA)
                {
                    i++;

                }


                var refInt = _Dal.DelExp(intA);
                if(refInt > 0)
                {
                    this.Exp_PageWriteLog(Log_Type.delete, "用户权限", intA);
                    SetData(0);
                    this.Exp_PageAlter("删除操作成功");
                    return;
                }
                else
                {
                    this.Exp_PageAlter("删除操作失败");
                    return;
                }
            });
        }

        protected void WebUserToolBar1_Button1(object sender, EventArgs e)
        {
            AdminPublic.Try(() =>
            {
                WebUserToolBar1.MainSetQuery();
                SetData(0);
            });
        }
    }
}
